/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.util;

import org.apache.commons.lang.Validate;

import java.util.regex.Pattern;

/**
 * 营改增：数据有效性验证
 *
 * @author MaShibo
 * @date 2017/11/26.
 */
public class DataValidationCheck {
    
    
    private DataValidationCheck() {
        throw new IllegalStateException("数据有效性验证工具类，无需初始化");
    }
    
    /**
     * 个人姓名：所有个人用户，联系人之类
     */
    public static final String USERNAME_REGEX = "(^[A-Za-z\\s·•.]+$)|(^[\u2E80-\uFE4F·•.]+$)";
    
    /**
     * 单位名称：所有单位名称类的字段，如发行方、公路方
     */
    public static final String COMPANYNAME_REGEX = "^[\u2E80-\uFE4F\\w()（）.\\-·•—/\\&《》]+$";
    
    /**
     * 地址：所有地址相关
     */
    public static final String ADDRESS_REGERX = "^[\u2E80-\uFE4F\\w.+()（）\\-\\—/&:：#&*《》、，,.。~·•“”\"\"【】\\[\\]]+$";
    
    /**
     * 特殊字符过滤：vehicleType，vehicleModel，用户卡model，OBU信息model
     * "
     */
    public static final String SPECIALCHAR_FILTER_REGEX = "^[\u2E80-\uFE4F()（）\\w.+\\-·•\\—/]*$";
    
    /**
     * 车辆识别代码
     */
    public static final String VEHICLE_VIN_REGEX = "^[\\w\\-/\\+]+$";
    
    /**
     * 车辆发动机号
     */
    public static final String VEHICLE_ENGINENUM_REGEX = "^[\\w\\-/\\+\\*\\s\u2E80-\uFE4F—]+$";
    
    /**
     * 护照、港澳居民来往内地通行证、台湾居民来往大陆通行证、统一社会信用代码证书、组织机构代码证、营业执照、律师事务所执业许可证
     */
    public static final String CERTIFINO_ONE_REGEX = "^[\\w()\\-（）—/]+$";
    
    /**
     * 身份证
     */
    public static final String CERTIFINO_IDCARD_REGEX = "^(11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|50|51|52|53|61|62|63|64|65)\\d{15}(\\d{1}|X)$";
    
    /**
     * 武警、军官证、事业单位法人证书、社会团体法人登记证书
     */
    public static final String CERTIFINO_TWO_REGEX = "^[\u2E80-\uFE4F\\w\\-—]+$";
    
    /**
     * 缺省证件类型：199、299
     */
    public static final String CERTIFINO_DEFAULT_REGEX = "^[\u2E80-\uFE4F()（）\\w.+\\-·•\\—/]*$";
    
    /**
     * 车牌号验证
     */
    public static final String VEHICLEPLATE_REGEX = "^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z0-9]{1}[A-Z0-9]{1}([京津沪渝桂蒙宁新藏冀晋辽吉黑苏浙皖赣闽鲁粤鄂湘豫川云贵陕甘青琼])?[A-HJ-Z0-9]{1}[A-NP-Z0-9]{3}[A-NP-Z0-9挂学警港澳领试超外]{1}([A-HJ-NP-Z0-9外])?_[0-9])|([A-Z0-9]{7}_[0-9])$";
    
    /**
     * 手机号验证
     */
    public static final String MOBILE_REGEX = "^1[3|4|5|7|8|9][0-9]{9}$";
    
    /**
     * 座机 + 手机
     */
    public static final String TEL_REGEX = "^0[1-9][0-9]{1,2}-[1-9][0-9]{5,7}(-[0-9]{1,4})?|1[3|4|5|7|8|9][0-9]{9}$";
    
    /**
     * 营业时间
     */
    public static final String BUSINESSHOURS_REGEX = "^[每月年节假周天第休息一二三四五六日至，.或星期:0-9\\-\\s,AMamPMpm]*$";
    
    public static boolean checkUserName(String input) {
        checkInputString(input);
        return Pattern.matches(USERNAME_REGEX, input);
    }
    
    public static boolean checkCompanyName(String input) {
        checkInputString(input);
        return Pattern.matches(COMPANYNAME_REGEX, input);
    }
    
    public static boolean checkAddress(String input) {
        checkInputString(input);
        return Pattern.matches(ADDRESS_REGERX, input);
    }
    
    public static boolean checkSpecialChar(String input) {
        checkInputString(input);
        return Pattern.matches(SPECIALCHAR_FILTER_REGEX, input);
    }
    
    public static boolean checkVehVin(String input) {
        checkInputString(input);
        return Pattern.matches(VEHICLE_VIN_REGEX, input);
    }
    
    public static boolean checkVehEngineNum(String input) {
        checkInputString(input);
        return Pattern.matches(VEHICLE_ENGINENUM_REGEX, input);
    }
    
    public static boolean checkCertifiNoOne(String input) {
        checkInputString(input);
        return Pattern.matches(CERTIFINO_ONE_REGEX, input);
    }
    
    public static boolean checkIdCard(String input) {
        checkInputString(input);
        return Pattern.matches(CERTIFINO_IDCARD_REGEX, input);
    }
    
    public static boolean checkCertifiNoTwo(String input) {
        checkInputString(input);
        return Pattern.matches(CERTIFINO_TWO_REGEX, input);
    }
    
    public static boolean checkCertifiNoDefault(String input) {
        checkInputString(input);
        return Pattern.matches(CERTIFINO_DEFAULT_REGEX, input);
    }
    
    public static boolean checkVehiclePlate(String input) {
        checkInputString(input);
        return Pattern.matches(VEHICLEPLATE_REGEX, input);
    }
    
    public static boolean checkMobile(String input) {
        checkInputString(input);
        return Pattern.matches(MOBILE_REGEX, input);
    }
    
    public static boolean checkTel(String input) {
        checkInputString(input);
        return Pattern.matches(TEL_REGEX, input);
    }
    
    public static boolean checkBusinessHours(String input) {
        checkInputString(input);
        return Pattern.matches(BUSINESSHOURS_REGEX, input);
    }
    
    private static void checkInputString(String input) {
        Validate.notNull(input, "待验证字符串不能为空");
    }

    public static void main(String[] args) {
        System.out.println(checkIdCard("610114198307122517"));
        System.out.println(checkCompanyName("默认名称"));
    }
}
